home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / reboot.zip / REBOOT.ASM < prev    next >
Assembly Source File  |  1988-02-06  |  8KB  |  297 lines

  1.     .xlist
  2.     if1
  3.     %out    REBOOT.ASM
  4.     endif
  5.     if2
  6.     %out    *** PASS 2
  7.     endif
  8.     name    REBOOT
  9.     title    DOS REBOOT PROGRAM
  10.     subttl    REBOOT
  11.     page    66,132
  12.     .list
  13.  
  14. ; ************************************************************************
  15. ; **                                    **
  16. ; ** filename:    reboot.asm                        **
  17. ; **                                    **
  18. ; **    Creates the file specified on the command line, defined by the    **
  19. ; ** environment variable REBOOT, C:\CLEAN by default, or no file if    **
  20. ; ** command line switch /F is given and performs a cold reboot if    **
  21. ; ** command line switch /C is given, or a warm boot by default.  The    **
  22. ; ** switch character "-" may be used instead of "/".            **
  23. ; **                                    **
  24. ; ************************************************************************
  25.  
  26. ; define bios and dos interrupts, functions, and services
  27. dos_term    equ    20H    ; DOS PROGRAM TERMINATION INTERRUPT
  28. dos_func    equ    21H    ; DOS FUNCTION INTERRUPT
  29. disp_string    equ    09H    ; DOS1 - DISPLAY STRING
  30. create        equ    3CH    ; DOS2 - CREATE FILE
  31. close        equ    3EH    ; DOS2 - CLOSE FILE
  32.  
  33. ; define constants
  34. lf        equ    0AH    ; ^J
  35. cr        equ    0DH    ; ^M
  36.  
  37. dos_flag_seg    equ    00000H        ; dos flags memory segment address
  38. dos_boot_flag    equ    00472H        ; dos reboot type flag offset
  39.  
  40. warm        equ    01234H        ; warm boot indicator
  41. cold        equ    0FFFFH        ; coldboot indicator
  42.  
  43. reset_seg    equ    0FFFFH        ; reset vector segment address
  44. reset_offset    equ    00000H        ; reset vector offset
  45.     page
  46. code    segment public
  47.     assume    cs:code,ds:code
  48.  
  49.     org    0            ; PSP
  50.  
  51. term_inst    dw    (?)        ; terminate (int 20H) instruction
  52. mem_size    dw    (?)        ; size of available memory
  53. reserved_0    db    (?)        ; reserved (normally 0)
  54. call_dispatch    db    5 dup (?)    ; call to DOS function dispatcher
  55. term_vec    dd    (?)        ; terminate vector
  56. brk_vec        dd    (?)        ; break vector
  57. err_vec        dd    (?)        ; error vector
  58. dos_use        db    22 dup (?)    ; used by DOS
  59. env_ptr        dw    (?)        ; environment string pointer
  60. dos_work    db    34 dup (?)    ; DOS work area
  61. int21_retf    db    3 dup (?)    ; int 21 and retf instructions
  62. reserved_1    db    2 dup (?)    ; reserved
  63. fcb_1_ext    db    7 dup (?)    ; FCB 1 extension
  64. fcb_1        db    9 dup (?)    ; FCB 1
  65. fcb_2_ext    db    7 dup (?)    ; FCB 2 extension
  66. fcb_2        db    20 dup (?)    ; FCB 2
  67. dta        equ    $        ; default dta
  68. attrib        equ    $ + 21        ; found file attribute
  69. ftime        equ    $ + 22        ; found file time stamp
  70. fdate        equ    $ + 24        ; found file date stamp
  71. fsize        equ    $ + 26        ; found file size
  72. fname        equ    $ + 30        ; found file asciiz filename
  73. parm_size    db    (?)        ; parameter size
  74. parm        db    127 dup (?)    ; parameter
  75.     page
  76.     org    100H            ;
  77.  
  78. reboot        proc    far
  79.  
  80.     mov    si,[2CH]        ; point to environment strings pointer
  81.     mov    si,[si]            ; load pointer to environment strings
  82.     push    si            ;
  83.     pop    es            ; es = base address of environment strings
  84.  
  85.     assume    es:nothing
  86.  
  87.     mov    si,0            ; initialize environment string offset
  88.  
  89. reboot_05:
  90.     mov    al,es:[si]        ; load environment character
  91.     cmp    al,0            ; end of environment strings?
  92.     jne    reboot_10        ; no - test for reboot string
  93.  
  94.     jmp    reboot_45        ; yes - parse command line
  95.  
  96. reboot_10:
  97.     lea    di,reboot$        ; point to reboot string
  98.     mov    cx,len_reboot$        ; load counter
  99.  
  100. reboot_15:
  101.     mov    al,es:[si]        ; load environment character
  102.     cmp    al,0            ; end of environment string?
  103.     jne    reboot_20        ; no - test for match with reboot$
  104.  
  105.     jmp    reboot_05        ; yes - test for end of environment
  106.  
  107. reboot_20:
  108.     cmp    al,[di]            ; match reboot$ character?
  109.     jne    reboot_25        ; no - search for end of string
  110.  
  111.     inc    si            ; yes -
  112.     inc    di            ;     - advance pointers
  113.     loop    reboot_15        ; done? - no - continue
  114.  
  115.     jmp    reboot_30        ; yes - decode environment string
  116.  
  117. reboot_25:
  118.     inc    si            ; advance environment pointer
  119.     mov    al,es:[si]        ; load environment character
  120.     cmp    al,0            ; end of environment string?
  121.     jne    reboot_25        ; no - continue
  122.  
  123.     inc    si            ; yes - point to next string
  124.     jmp    reboot_05        ; test for end of environment
  125.  
  126. reboot_30:
  127.     lea    di,filespec        ; point to filespec
  128.  
  129. reboot_35:
  130.     mov    al,es:[si]        ; load environment character
  131.     cmp    al," "            ; space?
  132.     jne    reboot_40        ; no - store character
  133.  
  134.     mov    al,0            ; yes - load terminator
  135.  
  136. reboot_40:
  137.     mov    [di],al            ; store
  138.     inc    si            ;
  139.     inc    di            ; advance pointers
  140.     cmp    byte ptr es:[si - 1],0    ; done?
  141.     jne    reboot_35        ; no - load next character
  142.  
  143. reboot_45:
  144.     mov    byte ptr[di],0        ; yes - terminate filespec
  145.     mov    ax,ds            ; load data segment pointer
  146.     mov    es,ax            ; set extra segment pointer
  147.  
  148.     assume    es:code
  149.  
  150.     cmp    parm_size,0        ; any parameter characters?
  151.     jne    reboot_50        ; yes - parse command line
  152.  
  153.     jmp    reboot_100        ; no - test for no file flag
  154.  
  155. reboot_50:
  156.     lea    di,filespec        ; yes - point to filespec
  157.     lea    si,parm + 1        ; point to command line parameters
  158.     mov    cx,0            ; clear filespec character counter
  159.  
  160. reboot_55:
  161.     lodsb                ; load parameter char
  162.     cmp    al," "            ; space?
  163.     jne    reboot_60        ; no - test for switch character
  164.  
  165.     mov    byte ptr[di],0        ; yes - store terminator
  166.     inc    di            ; advance pointer
  167.     jmp    reboot_55        ; load next character
  168.  
  169. reboot_60:
  170.     cmp    al,"/"            ; no - switch char?
  171.     je    reboot_65        ; yes - parse switch
  172.  
  173.     cmp    al,"-"            ; no - switch char?
  174.     je    reboot_65        ; yes - parse switch
  175.  
  176.     jmp    reboot_85        ; no - test for cr
  177.  
  178. reboot_65:
  179.     lodsb                ; load switch character
  180.     cmp    al," "            ; space?
  181.     je    reboot_55        ; yes - load next character
  182.  
  183.     cmp    al,cr            ; no - cr?
  184.     jne    reboot_70        ; no - force lower case
  185.  
  186.     jmp    reboot_90        ; yes - terminate filespec
  187.  
  188. reboot_70:
  189.     or    al,("A" xor "a")    ; force lower case
  190.     cmp    al,"f"            ; f?
  191.     je    reboot_75        ; yes - set no file flag
  192.  
  193.     cmp    al,"c"            ; no - c?
  194.     je    reboot_80        ; yes - set cold flag
  195.  
  196.     mov    ah,disp_string        ; no - indicate display string function
  197.     lea    dx,err_msg_1        ; point to message
  198.     int    dos_func        ; display message
  199.     int    dos_term        ; terminate program
  200.  
  201. reboot_75:
  202.     mov    nofile_flag,0FFH    ; set no file flag
  203.     jmp    reboot_65        ; load next char
  204.  
  205. reboot_80:
  206.     mov    cold_flag,0FFH        ; set cold flag
  207.     jmp    reboot_65        ; load next char
  208.  
  209. reboot_85:
  210.     cmp    al,cr            ; cr?
  211.     jne    reboot_95        ; no - store char
  212.  
  213. reboot_90:
  214.     jcxz    reboot_100        ; any filespec chars?
  215.                     ; no - test no file flag
  216.  
  217.     mov    byte ptr[di],0        ; yes -
  218.     mov    byte ptr[di + 1],0    ;     - store terminator
  219.  
  220.     jmp    reboot_100        ; test no file flag
  221.  
  222. reboot_95:
  223.     stosb                ; store char
  224.     inc    cx            ; advance filespec character counter
  225.     jmp    reboot_55        ; load next char
  226.  
  227. reboot_100:
  228.     cmp    nofile_flag,0        ; is no file flag set?
  229.     jne    reboot_115        ; yes - perform reboot
  230.  
  231.     lea    dx,def_name        ; no - point to default filename
  232.     lea    si,filespec        ; point to filespec
  233.     cmp    byte ptr[si],0        ; was filespec specified?
  234.     je    reboot_105        ; no - create default file
  235.  
  236.     lea    dx,filespec        ; yes - point to filespec
  237.  
  238. reboot_105:
  239.      mov    ah,create        ; indicate create file function
  240.     mov    cx,0            ; indicate normal attributes
  241.     int    dos_func        ; create file
  242.     mov    bx,ax            ; load handle
  243.     mov    ah,close        ; indicate close file function
  244.     int    dos_func        ; close file
  245.     mov    si,dx            ; load filespec pointer
  246.  
  247. reboot_110:
  248.     mov    al,byte ptr[si]        ; load current filename character
  249.     inc    si            ; advance pointer
  250.     cmp    al,0            ; found end of current filename?
  251.     jne    reboot_110        ; no - continue
  252.  
  253.     cmp    byte ptr[si],0        ; yes - end of filespec?
  254.     je    reboot_115        ; yes - perform reboot
  255.  
  256.     mov    dx,si            ; no - point to next filename
  257.     jmp    reboot_105        ; create next file
  258.  
  259. reboot_115:
  260.     mov    cx,warm            ; indicate warm boot
  261.     cmp    cold_flag,0        ; is cold flag set?
  262.     je    reboot_120        ; no - point to dos flags
  263.  
  264.     mov    cx,cold            ; yes - indicate cold boot
  265.  
  266. reboot_120:
  267.     mov    ax,dos_flag_seg        ; load dos flags memory segment address
  268.     mov    ds,ax            ; point to low memory
  269.  
  270.     assume    ds:nothing
  271.  
  272.     mov    ds:dos_boot_flag,cx    ; store boot indicator
  273.     mov    ax,reset_seg        ; load reset vector segment address
  274.     push    ax            ; store
  275.     mov    ax,reset_offset        ; load reset vector offset
  276.     push    ax            ;
  277.     ret                ;
  278.  
  279. reboot        endp
  280.     page
  281. ; data storage
  282.  
  283. nofile_flag    db    0        ; no file flag
  284. cold_flag    db    0        ; cold boot flag
  285.  
  286. reboot$        db    "REBOOT="    ; reboot string
  287. len_reboot$    equ    $ - reboot$    ; length of reboot string
  288.  
  289. def_name    db    "c:\clean",0,0    ; default asciiz filename
  290. filespec    db    80 dup (0)    ; asciiz filespec
  291.  
  292. err_msg_1    db    "reboot: usage: REBOOT [/fc] [file ...]",cr,lf,"$"
  293.     page
  294. code    ends
  295.  
  296.     end    reboot
  297.